<template>
  <div>
    <button @click="print">点击</button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      text: "",
      num: 1,
      path: "",
      pathbase: [],
    };
  },
  methods: {
    print() {
      this.$http
        .post("http://127.0.0.1:57380/scan", {
          pathname: "D:扫描书",
        })
        .then((res) => {
          this.path = res.data;
          res.data.forEach((item) => {
            var a = this.converData(item);
          });
        });
    },
    converData(data) {
      data = data.replace(/[\n\r]/g, "");
      data = data.replace(/[\n\r]/g, "");
      function utf8_to_b64(str) {
        return window.btoa(unescape(encodeURIComponent(str)));
      }

      function b64_to_utf8(str) {
        return decodeURIComponent(escape(window.atob(str)));
      }

      // Usage:
      var a = utf8_to_b64(data); // JTI1dTI3MTMlMjUyMCUyNUUwJTI1MjBsYSUyNTIwbW9kZQ==

      var raw = b64_to_utf8(a); // "✓ à la mode"!"

      // var rawLength = raw.length;
      // var buff = new ArrayBuffer(rawLength);

      // var array = new Uint8Array(buff);

      // for (var i = 0; i < rawLength; i++) {
      //   array[i] = raw.charCodeAt(i);
      // }
    },
  },
};
</script>
<style lang="less" scoped>
.pdf {
  width: 50%;
}
</style>
